package com.sx.jys.ui.vm

import com.sx.jys.app.net.HttpRequestCoroutine
import com.sx.jys.app.until.CacheUntil
import com.sx.jys.app.until.request2
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.livedata.BooleanLiveData
import me.hgj.jetpackmvvm.callback.livedata.StringLiveData

class LoginVm : BaseViewModel() {
    val phoneField = StringLiveData()
    val passwordField = StringLiveData()
    val loginSuccessEvent = BooleanLiveData()


    fun reqLogin() {
        request2({ HttpRequestCoroutine.login(phoneField.value, passwordField.value) }, {
            CacheUntil.setToken(it.token)
            CacheUntil.setId(it.id)
            loginSuccessEvent.value = true
        }, isShowDialog = true)
    }
}